package com.t3go.t3_map.utils;

import com.t3go.t3_map.entity.Annotation;
import com.t3map.api.map.model.T3Marker;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MarkerUtil {

    public static String getMarkerId(Map<String, List<T3Marker>> markerMap, T3Marker marker) {
        if (markerMap == null || marker == null) {
            return null;
        }
        for (Map.Entry<String, List<T3Marker>> item : markerMap.entrySet()) {
            List<T3Marker> markers = item.getValue();

            if (markers == null || markers.isEmpty()) {
                continue;
            }
            for (T3Marker temp : markers) {
                if (temp == marker) {
                    return item.getKey();
                }
            }
        }
        return null;
    }

    public static void removeMarker(Map<String, List<T3Marker>> markerMap) {
        if (markerMap == null || markerMap.isEmpty()) {
            return;
        }
        Collection<List<T3Marker>> markers = markerMap.values();
        for (List<T3Marker> list : markers) {
            removeMarker(list);
        }
    }

    public static void removeMarker(List<T3Marker> markers) {
        if (markers != null) {
            for (T3Marker marker : markers) {
                marker.remove();
            }
        }
    }

    public static void removeMarker(Map<String, List<T3Marker>> markerMap, List<Annotation> annotations) {
        if (markerMap == null || annotations == null) {
            return;
        }
        for (Annotation annotation : annotations) {
            List<T3Marker> markers = markerMap.remove(annotation.getUid());
            removeMarker(markers);
        }
    }
}
